package com.fudan.sys.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.fudan.framework.base.BaseDao;
import com.fudan.sys.entity.Role;

@Repository
public interface RoleDao extends BaseDao<Role>{

	@Query(nativeQuery=true,value="insert into t_role_permission(role_id,permission_id) values (:roleId,:permissionId)")
	@Modifying
	public Integer insertPermission(@Param("roleId") Integer roleId, @Param("permissionId") String permissionId);
	@Query(nativeQuery=true,value="delete from t_role_permission where role_id=:roleId")
	@Modifying
	public Integer deletePermission(@Param("roleId") Object roleId);
	@Query(nativeQuery=true,value="select permission_id from t_role_permission where role_id=:roleId")
	public List<Integer> findPermission(@Param("roleId") Integer roleId);
	@Query(nativeQuery=true,value="select p.code from t_user u left join t_role r on u.role_id=r.id left join t_role_permission rp on rp.role_id=r.id left join t_permission p on p.id=rp.permission_id where u.id=:userId")
	public List<String> findPermissionCodeByUserId(@Param("userId") Object userId);
}
